Skip to content

[COMPRESS-722] Introduce handling of entries compressed by a specific method#765

Open
uvoigt wants to merge 2 commits intoapache:masterfrom
uvoigt:feat/COMPRESS-722
Open

[COMPRESS-722] Introduce handling of entries compressed by a specific method#765
uvoigt wants to merge 2 commits intoapache:masterfrom
uvoigt:feat/COMPRESS-722

Conversation

@uvoigt
Copy link
Copy Markdown

@uvoigt uvoigt commented Mar 28, 2026

Content

This introduces the mode autoCompress of ZipArchiveOutputStream. If enabled, the stream uses factories of the implemented methods to create a compressing OutputStream per entry. When using this mode, it is no longer necessary to explicitly set the uncompressed size of an entry.

Additional modifications:

  • It is no longer necessary to close explicitly close the last archive entry.

Thanks for your contribution to Apache Commons! Your help is appreciated!

Before you push a pull request, review this list:

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • [ x Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

… method in ZipArchiveOutputStream

- implicitly close entries when writing
@mehmet-karaman
Copy link
Copy Markdown
Contributor

mehmet-karaman commented Mar 30, 2026

@garydgregory is it possible to add copilot to the reviewers list to have a raw check?

https://docs.github.com/en/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review


if (entry != null) {
throw new ArchiveException("This archive contains unclosed entries.");
closeArchiveEntry();
Copy link
Copy Markdown
Contributor

@mehmet-karaman mehmet-karaman Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep the API compatible with older clients, wouldn’t it be better to execute this only when the isAutoCompressed flag is set and otherwise still throw the exception?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can close this.. There was a todo in the ArchiveOutputStreamTest which is resolved by this change, so it was somehow planned to do..

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is tested in testAutoCompressZstd(ZipMethod zipMethod) for auto-compress and in testAutoCompressFalsePreservesLegacyBehavior() for user specified compressing.

aos2.putArchiveEntry(aos2.createArchiveEntry(dummy, "dummy"));
aos2.write(dummy);

// TODO check if second putArchiveEntry() can follow without closeAE?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah.. sorry didn't saw that there is a todo.. Might be also a good time to fix this..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one can also be closed.

@mehmet-karaman
Copy link
Copy Markdown
Contributor

From my perspective, this looks good. All workarounds and edge cases seem to be covered and the implementation as well as the Javadocs are clear and understandable.

@uvoigt uvoigt force-pushed the feat/COMPRESS-722 branch from 3ea743b to 6c8265a Compare March 30, 2026 15:21
@uvoigt
Copy link
Copy Markdown
Author

uvoigt commented Mar 30, 2026

Fixed a problem with the builder construction. I was not that familiar with AbstractBuilder.

…uilder construction without file and fix an inconsistency
@uvoigt uvoigt force-pushed the feat/COMPRESS-722 branch from 6c8265a to 6ae0742 Compare March 30, 2026 15:27
@mehmet-karaman
Copy link
Copy Markdown
Contributor

Hi @garydgregory ,

do you need anything for this PR, or is something still missing?

Best regards
Mehmet

@garydgregory
Copy link
Copy Markdown
Member

Hello @mehmet-karaman

Please be patient. This is not the only issue or Commons component that needs attention 😉

@uvoigt
Copy link
Copy Markdown
Author

uvoigt commented Apr 2, 2026

Hello @mehmet-karaman

Please be patient. This is not the only issue or Commons component that needs attention 😉

Happy Easter!

Hope you're enjoying some free time!

Thank you for your work on these kinds of software projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants